package diary

import (
	"context"
	"time"

	"go-weixin/app/diary/api/internal/svc"
	"go-weixin/app/diary/api/internal/types"
	"go-weixin/app/diary/rpc/pb/proto/diary"

	"github.com/zeromicro/go-zero/core/logx"
)

type DiaryDeleteLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDiaryDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DiaryDeleteLogic {
	return &DiaryDeleteLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DiaryDeleteLogic) DiaryDelete(req *types.DiaryDeleteReq) (resp *types.DiaryDeleteResp, err error) {
	ctx, canelFunc := context.WithTimeout(context.Background(), 5*time.Second)
	defer canelFunc()
	_, err = l.svcCtx.DiaryRpc.DiaryDelete(ctx, &diary.DiaryDeleteReq{
		Id: req.Id,
	})
	if err != nil {
		return nil, err
	}
	return
}
